using System;
using System.Collections;
using System.Runtime.Serialization;

namespace ICeFramework.Common.DataLayer
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks></remarks>
    /// <example></example>
    [Serializable, DataContract]
    public class DataParameterCollection 
	{
        #region private Hashtable _parameters
        /// <summary>
        /// Get/Sets the _parameters of the <see cref="ICeFramework.Common.DataLayer.DataParameterCollection"/>
        /// </summary>
        [DataMember]
        private Hashtable _parameters = new Hashtable();
        #endregion

        #region public DataParameterCollection()
        /// <summary>
        /// Initializes a new instance of the <b>DataParameterCollection</b> class.
        /// </summary>
        public DataParameterCollection()
        {

        }
        #endregion

        #region public void Add(DataParameter parameter)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameter"></param>
        public void Add(DataParameter parameter)
        {
            _parameters.Add(parameter.ParameterName, parameter);
        }
        #endregion

        #region public void Clear()
        /// <summary>
        /// 
        /// </summary>
        public void Clear()
        {
            _parameters.Clear();
        }
        #endregion

        #region public DataParameter this[int index]
        /// <summary>
        /// Gets the <see cref="DataParameter"/> item identified by the given arguments of the DataParameterCollection
        /// </summary>
        /// <value></value>
        public DataParameter this[int index]
        {
            get { return (DataParameter)_parameters[index]; }
        }
        #endregion

        #region public DataParameter this[string index]
        /// <summary>
        /// Get/Sets the <see cref="DataParameter"/> item identified by the given arguments of the DataParameterCollection
        /// </summary>
        /// <value></value>
        public DataParameter this[string index]
        {
            get { return (DataParameter)_parameters[index]; }
            set { _parameters[value.ParameterName] = value; }
        }
        #endregion

        #region public IEnumerator GetEnumerator()
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IEnumerator GetEnumerator()
        {
            return _parameters.Values.GetEnumerator();
        }
        #endregion

        #region public object[] ParametersValue
        /// <summary>
        /// Gets the ParametersValue of the DataParameterCollection
        /// </summary>
        /// <value></value>
        public object[] ParametersValue
        {
            get
            {
                ArrayList parameters = new ArrayList();
                foreach (object o in _parameters.Values)
                    parameters.Add(o);
                return parameters.ToArray();
            }
        }
        #endregion

        #region public object[] ParametesKey
        /// <summary>
        /// Gets the ParametesKey of the DataParameterCollection
        /// </summary>
        /// <value></value>
        public object[] ParametesKey
        {
            get
            {
                ArrayList parameters = new ArrayList();
                foreach (object o in _parameters.Keys)
                    parameters.Add(o);
                return parameters.ToArray();
            }
        }
        #endregion

        #region public override string ToString()
        /// <summary>
        /// Returns a <see cref="string"/> that represents the current <see cref="ICeFramework.Common.DataLayer.DataParameterCollection"/>.
        /// </summary>
        /// <returns>A <see cref="string"/> that represents the current <see cref="ICeFramework.Common.DataLayer.DataParameterCollection"/>.</returns>
        public override string ToString()
        {
            string rez = string.Empty;
            foreach (string key in _parameters.Keys)
            {
                rez += _parameters[key].ToString() + "   ,\r\n ";
            }
            return rez;
        }
        #endregion
	}
}
